package com.example.administrator.androidui5;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    Button mBtnCompute;
    TextView mTvmessage;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        initEvent();
    }

    interface  OnComputed{
        void showMessage(String message);
    }
//声明接口，将会把ｍｅｓｓａｇｅ的信息显示到Ａｃｔｉｖｉｔｙ
    private void initView() {
        mBtnCompute = findViewById(R.id.btn_button1);
        mTvmessage= findViewById(R.id.tv_message);
    }

    private void initEvent() {
        mBtnCompute.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyDialog dialog = new MyDialog(MainActivity.this, new OnComputed() {
                    @Override
                    public void showMessage(String message) {
                        mTvmessage.setText(message);
                    }
                });
                dialog.show();
            }
        });
    }

}
